Skip to content

Instantly share code, notes, and snippets.

@nymous
nymous / README.md
Last active May 17, 2024 15:10
Logging setup for FastAPI, Uvicorn and Structlog (with Datadog integration)

Logging setup for FastAPI

This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.

Then, you can use Structlog loggers or standard logging loggers, and they both will be processed by the Structlog pipeline (see the hello() endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!

Requests are assigned a correlation ID with the asgi-correlation-id middleware (either captured from incoming request or generated on the fly). All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented. This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog. You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom

@Horusiath
Horusiath / Fiber.fs
Last active May 17, 2024 15:09
Custom fibers implementation in F#
/// MIT License
///
/// Copyright (c) 2024 Bartosz Sypytkowski
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
@eulerfx
eulerfx / EventSourcingMonoids.fs
Last active May 17, 2024 15:09
F# event-sourcing with monoids
type Monoid<'a> = {
unit : 'a
op : 'a -> 'a -> 'a
}
let endo<'a> =
{ unit = id
op = fun (f:'a -> 'a) (g:'a -> 'a) -> f << g }
@ezracb
ezracb / VMware Workstation Pro and Fusion Pro Licence Keys
Created April 9, 2021 14:43
VMware Workstation Pro and Fusion Pro Licence Keys
Obviously using these keys may be a grey area. I use them for my computer, but there are no guarentees VMware won't sue you if you use them in a commercial environment.
VMware Workstation 16
YF390-0HF8P-M81RQ-2DXQE-M2UT6
VMware Fusion Pro 12
YF390-0HF8P-M81RQ-2DXQE-M2UT6
As far as I know, this key works on both Fusion and Workstation.
@intergalacticspacehighway
intergalacticspacehighway / CollapsibleText.tsx
Last active May 17, 2024 15:08
Collapsible text using reanimated
import { useEffect, useRef } from "react";
import { View } from "react-native";
import Animated, {
useAnimatedStyle,
useSharedValue,
} from "react-native-reanimated";
// Example
export default function App() {
@maddouri
maddouri / build-static-python.sh
Created December 6, 2015 22:42
A simple script that builds static versions of Python and LibPython using musl-libc
#!/bin/bash
# set -eux
# This a simple script that builds static versions of Python and LibPython using musl-libc
# Find the associated article at: http://general-purpose.io/2015/12/06/compiling-python-and-libpython-statically-using-musl-libc/
WORKING_DIR="/code/static-python"
MUSL_PREFIX="/code/static-python/musl"
PY_PREFIX="/code/static-python/python"

The following are steps to set up Azure AD as an Identity Provider for an on-prem Kubernetes cluster.

Starting point:

  • Azure Subscription
  • On-prem Kubernetes cluster (in my case RKE2 v1.27.12+rke2r1)

The scenario is pretty straightforward:

I want to connect from my Workstation (Windows/Linux/Mac) to an on-prem Kubernetes cluster and authenticate to is using Azure AD.

@aamiaa
aamiaa / CompleteDiscordQuest.md
Last active May 17, 2024 15:03
Complete Recent Discord Quest

Complete Recent Discord Quest

Note

This no longer works in browser!

Note

This no longer works if you're alone in vc! Somebody else has to join you!

How to use this script:

  1. Accept the quest under User Settings -> Gift Inventory
@simonw
simonw / recover_source_code.md
Last active May 17, 2024 15:03
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});